<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>测试支付</title>
    <link rel="shortcut icon" href="${ctxPath}/static/favicon.ico">
    <script src="${ctxPath}/static/js/jquery.min.js?v=2.1.4"></script>
</head>
<body>
    <H2>支付页面</H2>
    <input type="button" style="margin-left:400px;height: 40px;width: 100px;background-color:gray" value="支付0.01元钱" onclick="toPay()">
</body>
<script>
    function  toPay() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "${ctxPath}/wx/pay/unifiedorder",
            data: {
                appointmentTime: 1568769408000,
                deliveryFee:0,
                phone:15982276786,
                totalFee:1,
                businessType:1,
                addressId:1,
                type:1,
                remark:"速度",
                consumerId:1,
                artificerId:1
            },
            success: function(result){
                if(result.status=="0000"){
                    function onBridgeReady(){
                        WeixinJSBridge.invoke(
                            'getBrandWCPayRequest', {
                                "appId":result.data.appId,     //公众号名称，由商户传入
                                "timeStamp": result.data.timeStamp,         //时间戳，自1970年以来的秒数
                                "nonceStr":result.data.nonceStr, //随机串
                                "package":result.data.packages,
                                "signType":"MD5",         //微信签名方式：
                                "paySign":result.data.paySign //微信签名
                            },
                            function(res){
                                if(res.err_msg == "get_brand_wcpay_request:ok" ){
                                    // 使用以上方式判断前端返回,微信团队郑重提示：
                                    //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
                                    alert("支付成功!");
                                }else if(res.err_msg == "get_brand_wcpay_request:cancel"){

                                }else{

                                }
                            });
                    }
                    if (typeof WeixinJSBridge == "undefined"){
                        if( document.addEventListener ){
                            document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                        }else if (document.attachEvent){
                            document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                            document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                        }
                    }else{
                        onBridgeReady();
                    }
                }
            },
            error:function(data){
                alert("下单异常，请稍后再试!");
            }
        });
    }
</script>
</html>